import React, { Component } from 'react';
import { connect } from 'react-redux';
import { Button, Form, Input, Radio } from 'antd';
import { Link } from 'react-router-dom';
import action from "../../../store/action";
import { passCation, openNotification } from '../../../component/Notification';


class index extends React.Component {
    constructor() {
        super();
        this.state = {

        }
    }
    render() {
        const {TextArea}=Input;
        const data = this.props.edit_data[0];
        const layout = {
            labelCol: {
                span: 5,
            },
            wrapperCol: {
                span: 15,
            },
        };
        const tailLayout = {
            wrapperCol: {
                offset: 3,
                span: 15,
            },
        };
        const onFinish = values => {
            console.log(values);
            const list = {
                code: data.code,
                pname: values.pname,
                memo: values.memo,
                address: values.address,
                postalCode: values.code,
                tel: values.tel,
                fax: values.fax,
                homePage: values.homePage,
                email: values.email,
                intro: values.intro
            }

            this.$axios.get('/manager/api/isOrganizationNameExist', this.$qs.stringify({ name: values.pname })).then((res) => {
                if (res) {
                    this.$axios.post('/manager/api/updateOrganization', list).then((res) => {
                        if (res.status === 1) {
                            this.props.history.push('/admin');
                            passCation('保存成功!')
                        }
                    }).catch((err) => {
                        console.log(err);
                    })
                }
            }).catch((err) => {
                console.log(err);
                openNotification('单位名称已存在!')
            })
        };

        const onFinishFailed = errorInfo => {
            console.log(errorInfo);
        };

        return <div>
            <div style={{ textAlign: 'center', fontSize: 20 }}>
                修改单位(中国航空工业集团公司北京航空材料研究院（621所）)信息
            </div>
            <div style={{ margin: 30 }}>
                <Form
                    {...layout}
                    name="basic"
                    initialValue={{
                        remember: true,
                    }}
                    onFinish={onFinish}
                    onFinishFailed={onFinishFailed}
                >
                    <div className="add_flex">
                        <Form.Item
                            name="pname"
                            label="单位名称:"
                            rules={[
                                {
                                    required: true,
                                    message: '内容不能为空!',
                                },
                            ]}
                            initialValue={data.pname}
                        >
                            <Input placeholder='请输入单位名称' />
                        </Form.Item>

                        <Form.Item name="address" label="地址:" rules={[
                            {
                                required: true,
                                message: '内容不能为空!',
                            },
                        ]} initialValue={data.address}>
                            <Input type="textarea" placeholder='请输入详细地址' />
                        </Form.Item>
                    </div>
                    <div className='add_flex'>
                        <Form.Item name="tel" label="联系电话:" rules={[
                            {
                                required: true,
                                message: '内容不能为空!',
                            },
                        ]} initialValue={data.tel}>
                            <Input type="textarea" placeholder='请输入联系电话' />
                        </Form.Item>
                        <Form.Item name="fax" label="传真:" rules={[
                            {
                                required: true,
                                message: '内容不能为空!',
                            },
                        ]} initialValue={data.fax}>
                            <Input type="textarea" placeholder='请输入传真' />
                        </Form.Item>
                    </div>
                    <div className='add_flex'>
                        <Form.Item name="homePage" label="主页:" rules={[
                            {
                                required: true,
                                message: '内容不能为空!',
                            },
                        ]} initialValue={data.homePage}>
                            <Input type="textarea" placeholder='请输入主页地址' />
                        </Form.Item>
                        <Form.Item name="email" label="邮箱:" rules={[
                            {
                                required: true,
                                message: '内容不能为空!',
                            },
                        ]} initialValue={data.email}>
                            <Input type="textarea" placeholder='请输入邮箱地址' />
                        </Form.Item>
                    </div>
                    <div className='add_flex'>
                        <Form.Item name="memo" label="备注:" rules={[
                            {
                                required: true,
                                message: '内容不能为空!',
                            },
                        ]} initialValue={data.memo}>
                            <Input type="textarea" placeholder='请输入备注' />
                        </Form.Item>
                        <Form.Item name="code" label="邮编:" rules={[
                            {
                                required: true,
                                message: '内容不能为空!',
                            },
                        ]} initialValue={data.postalCode}>
                            <Input type="textarea" />
                        </Form.Item>
                    </div>
                    <Form.Item name="intro" label="简介:" style={{ width: '40%', marginLeft: '5%' }} initialValue={data.intro}>
                        <TextArea allowClear autoSize={true} />
                    </Form.Item>

                    <Form.Item {...tailLayout}>
                        <Button type="primary" htmlType="submit" style={{ margin: '20px 10px' }}>
                            保存
                    </Button>
                        <Link to='/admin'><Button type='primary'>返回</Button></Link>
                    </Form.Item>
                </Form>

            </div>
        </div>
    }
}

export default connect((state) => ({ ...state.custom }), action.custom)(index);